﻿using System;
using BoldBrick.Core.Logging;

namespace BoldBrick.SharePoint.CommonControls.Logging
{
	/// <summary>
	/// Special class for logging in features during activation and deactivation. 
	/// When standard approach is used, there ase some bugs during deployment of solution
	/// </summary>
	public static class FeatureLogger
	{
		/// <summary>
		/// Created instance of logger
		/// </summary>
		/// <typeparam name="TType">Type of class that will log</typeparam>
		/// <returns>Returns instance of logger ready to log</returns>
		private static ILogger GetLogger<TType>()
		{
			return Logger.GetLogger(typeof (TType));
		}
		
		/// <summary>
		/// Write the log
		/// </summary>
		/// <typeparam name="TFeatureType">Type of the class of the feature</typeparam>
		/// <param name="logLevel">Level of log information</param>
		/// <param name="ex">Exception if there is some</param>
		/// <param name="message">Message of the log</param>
		/// <param name="pars">Atributes for message if message contains format placeholder</param>
		public static void Write<TFeatureType>(LogLevel logLevel, Exception ex, string message, params object[] pars)
		{
			ILogger log = GetLogger<TFeatureType>();
			log.Write(logLevel, ex, message, pars);
		}

		/// <summary>
		/// Write the log
		/// </summary>
		/// <typeparam name="TFeatureType">Type of the class of the feature</typeparam>
		/// <param name="logLevel">Level of log information</param>
		/// <param name="message">Message of the log</param>
		/// <param name="pars">Atributes for message if message contains format placeholder</param>
		public static void Write<TFeatureType>(LogLevel logLevel, string message, params object[] pars)
		{
			ILogger log = GetLogger<TFeatureType>();
			log.Write(logLevel, message, pars);
		}
	}
}
